package com.gambi.tapestry.services.gwt;

import java.io.IOException;
import java.io.OutputStream;

import org.apache.tapestry5.services.ComponentEventResultProcessor;
import org.apache.tapestry5.services.RequestGlobals;

import com.gambi.tapestry.utils.GWTBoolean;
import com.gambi.tapestry.utils.GWTNull;
import com.gambi.tapestry.utils.GWTVoid;

// This is used to return the plain response whenever there is a bubbling-blocking method handler
public class GWTComponentEventPlainResultProcessor implements
		ComponentEventResultProcessor {

	private final RequestGlobals requestGlobals;

	public GWTComponentEventPlainResultProcessor(RequestGlobals requestGlobals) {
		this.requestGlobals = requestGlobals;
	}

	public void processResultValue(Object value) throws IOException {
		System.out.println("GWTComponentEventPlainResultProcessor.processResultValue() This is blocking ");
		// Is this a Default for GWT ?
		OutputStream os = requestGlobals.getResponse().getOutputStream("UTF-8");
		os.write(value.toString().getBytes());
		os.close();
	}
}
